package com.yhb.channel.exception;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
public class PayChannelException extends RuntimeException {
    protected Long code;
    protected String message;
    protected Throwable nestedException;
    protected String channelName;
    protected String channelType;
    protected String extendInfo;  // 约定: 当 errorCode 是 ChannelConstant.PAY_ERROR 时, extendInfo 就是 flowId

    public PayChannelException () {

    }

    public PayChannelException(Long code, String message) {
        super();
        this.code = code;
        this.message = message;
    }

    public PayChannelException(Long code, String message, Throwable nestedException) {
        super(nestedException);
        this.code = code;
        this.message = message;
        this.nestedException = nestedException;
    }

    public PayChannelException(String code, String message, Throwable nestedException) {
        super(nestedException);
        this.code = Long.parseLong(code, 10);
        this.message = message;
        this.nestedException = nestedException;
    }

    @Override
    public String toString() {
        return "PayChannelException{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", nestedException=" + nestedException +
                ", channelName='" + channelName + '\'' +
                ", channelType='" + channelType + '\'' +
                ", extendInfo='" + extendInfo + '\'' +
                '}';
    }
}
